<template>
	<view class="home" v-if="info">
		<u-navbar bgColor="#FFFFFF" placeholder
			leftIconColor="#000" title="邀请好友" @leftClick="back">

			<view class="right" slot="right" @click="toPage('/pages/Invite/rankingList')">排行榜</view>
		</u-navbar>
		<view class="qrbox">
			<view class="title">
				<text>我的专属邀请码 </text>
				<text class="qr">{{info.code}}</text>
				<!-- <image src="../../static/images/share/fz.png" @click="toCopy(info.code)" mode="aspectFit" class="fzico">
				</image> -->
			</view>
			<div class="qrcode" ref="qrCodeUrl">
				<view class="qrcodeBox">
					<view class="title1">
						<view class="tit" >
							疯传数藏
						</view>
						<text>每个人的数藏平台</text>
					</view>
					<view class="qrImg">
						<image :src="info.poster_path" mode="aspectFill" class="img"></image>
					</view>
				</view>
			</div>

			<view class="yqlink">
				<view class="content">
					<view class="link">
						<text class="text">我的邀请链接</text>
						<text class="url">{{info.poster_url}}</text>
					</view>
					<view class="copyBtn" @click="toCopy(info.poster_url)">
						复制
					</view>
				</view>
				
				<!-- <image src="../../static/images/share/fz.png" @click="toCopy(info.poster_url)" mode="aspectFit"
					class="fzico"></image> -->
			</view>
			<view class="btn" @click="saveShareImg(info.poster_path)">
				生成海报转发
			</view>
		</view>

		<!--<view class="nav-box">
			<view class="nav-top">
				<view class="nav-title " :class="active==1?'act':''" @click="tochanger(1)">
					邀请排行
				</view>
				<view class="nav-title" :class="active==2?'act':''" @click="tochanger(2)">
					邀请记录
				</view>
			</view>
			<scroll-view scroll-y class="draw-lots-list" @scrolltolower="Drawlist()">
				<view class="list">
					<block v-if="active==1">
						<view class="item" v-for="(item,i) in list" :key="i">
							<view class="left">
								<text class="sort">{{i+1}}</text>
								<text class="nickname">{{item.nickname}}</text>
							</view>
							<view class="valid">
								<text>{{item.pay_num}}</text>
								<text class="dw">人</text>
							</view>	
							<view class="right">
								<text>{{item.total}}</text>
								<text class="dw">人</text>
							</view>
						</view>
						<block v-if="list.length<1">
							<Empty text="暂无数据" :type='1'></Empty>
						</block>
						<view class="more" v-if="total>0" @tab="Drawlist">{{total>list.length?'加载更多':'已加载全部'}}</view>
					</block>

					<block v-if="active==2">
						<view class="items" v-for="(item,i) in lists" :key="i">
							<view class="left">
								<view class="name">
									{{item.mobile}}
								</view>
								<view class="time">
									{{item.create_time}}
								</view>
							</view>
							<view class="right">
								<view v-if="item.paystatus > 0" class="ispay"><u-icon name="checkmark" color="#fff" size="18"></u-icon></view>
								<text class="ysm"
									:class="item.real_name_status==0?'nyz':''">{{item.real_name_status==0?'未实名':'已实名'}}</text>
									
							</view>
						</view>
						<block v-if="lists.length<1">
							<Empty text="暂无数据" :type='1'></Empty>
						</block>
						<view class="more" v-if="totals>0" @tab="Drawlist">{{totals>lists.length?'加载更多':'已加载全部'}}</view>
					</block>

				</view>

			</scroll-view>
		</view>-->


		<u-popup :show="show" @close="close" @open="open" bgColor="transparent">
			<view class="">
				<ShareCard :data='info' />
			</view>
		</u-popup>
		<XQ-GeneratePoster ref="draw" :info='option' v-if="shows" :share='shows' @close="closes" />
	</view>
</template>

<script>
	import ShareCard from '@/components/shareCard.vue'
	import Empty from '@/components/Empty.vue'
	import XQGeneratePoster from '@/components/friendCard.vue'
	import {mixin} from '@/Mixins/mixin.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		components: {
			ShareCard,
			Empty,
			XQGeneratePoster
		},
		mixins: [mixin],
		computed: {
			...mapState(['userInfo'])
		},
		data() {
			return {
				show: false,
				active: 1,
				shows: false,
				info: '',
				page: 1,
				list: [],
				lists: [],
				option: {},
				total: '',
				totals: '',
				scrollTop: 0,

			}
		},

        onLaunch() {
        	plus.navigator.closeSplashscreen();
        },
		mounted() {
			this.creatQrCode()
			// this.getList()
		},
		onReachBottom() {

		},
		// onPageScroll(e) {
		// 	this.scrollTop = e.scrollTop;
		// },
		methods: {
			Drawlist() {
				if (this.active == 1 && this.list.length < this.total) {
					this.page += 1
					this.getList()
				} else if (this.lists.length < this.totals) {
					this.page += 1
					this.getList()
				}
			},
			// 保存到系统相册			
			saveShareImg() {
				this.shows = true
				this.option = this.info
				this.option.nickName = this.userInfo.nickname || '疯传数藏'
			},
			closes(e) {
				this.shows = e
			},
			async getList() {
				this.loading = true
				let res = await this.$http({
					url: this.active == 1 ? this.$api.getInviteTopList : this.$api.getInviteUserList,
					method: 'POST',
					hideLoading: true,
					data: {
						page_size: 2000,
						page: this.page,
					}
				})
				this.loading = false
				if (this.page == 1) {
					if (this.active == 1) {
						this.list = []
					} else {
						this.lists = []
					}
				}
				if (res.code == 200) {

					if (this.active == 1) {
						this.list = this.list.concat(res.data.data)
						this.total = res.data.total
					}
					if (this.active == 2) {
						this.lists = this.lists.concat(res.data.data)
						this.totals = res.data.total
					}
				}

			},

			tochanger(e) {
				if (this.loading) {
					this.$u.toast('数据加载中')
					return
				}
				this.page = 1
				this.active = e
				this.getList()
			},
			back() {
				uni.navigateBack({
						delta:1,//返回层数，2则上上页
					})
			},
			toCopy(val) {
				uni.setClipboardData({
					data: val,
					success: () => {
						uni.showToast({
							icon: 'none',
							title: '复制成功'
						});
					}
				});
			},
			async creatQrCode() {
				let data = await this.$http({
					url: this.$api.inviteFriends,
					method: 'POST',
					hideLoading: true,
					data: {}
				})
				if (data.code == 200) {
					this.info = data.data
				}

			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			toShare() {
				this.show = true
			},
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		min-height: 100vh;
		padding-top: 600rpx;
		box-sizing: border-box;
		background: #fff url('../../static/images/invite_bg.png') no-repeat;
		background-size: 100% auto;
		background-position: 0 120rpx;

		.icr {
			height: 40rpx;
			width: 40rpx;
		}
		
		.right {
			width: 126rpx;
			height: 52rpx;
			background: #468EFF;
			border-radius: 28rpx;
			font-weight: 600;
			color: #FFFFFF;
			font-size: 26rpx;
			text-align: center;
			line-height: 52rpx;
		}

		.qrbox {
			display: flex;
			// width: 574rpx;
			// height: 568rpx;
			// background: #FFFFFF;
			border-radius: 40rpx;
			// margin: 0rpx auto 20rpx;
			flex-direction: column;
			align-items: center;
			padding: 60rpx;
			// padding: 70rpx 60rpx;

			.title {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 28rpx;
				font-weight: 600;
				color: #333333;
				line-height: 40rpx;

				.qr {
					font-size: 64rpx;
					font-weight: 600;
					color: #2A4D9D;
					// margin-left: 20rpx;
					// margin-right: 10rpx;
					margin: 24rpx 0;
				}

				.fzico {
					height: 28rpx;
					width: 28rpx;
				}

			}

			.yqlink {
				// align-items: center;
				// font-size: 24rpx;
				// font-weight: 600;
				// color: #000000;
				// white-space: nowrap;
				width: 630rpx;
				height: 158rpx;
				background: #FFFFFF;
				border-radius: 8rpx;
				border: 1rpx solid #C8C8D4;
				padding: 24rpx;
				box-sizing: border-box;
				
				.content {
					display: flex;
					align-items: center;
					justify-content: space-between;
					.link {
						width: 434rpx;
						display: flex;
						flex-direction: column;
						flex-wrap: wrap;
						.text {
							font-size: 28rpx;
							font-weight: 600;
							color: #1F2037;
						}
						.url {
							font-size: 24rpx;
							color: #737482;
							margin: 10rpx 0;
							overflow-wrap: break-word;
						}
					}
					.copyBtn {
						width: 112rpx;
						height: 56rpx;
						background: #468EFF;
						border-radius: 4rpx;
						color: #fff;
						font-size: 28rpx;
						text-align: center;
						line-height: 56rpx;
					}
				}

				.fzico {
					height: 42rpx;
					width: 42rpx;
				}

				// .link {
				// 	font-size: 20rpx;
				// 	font-weight: 600;
				// 	color: #000000;
				// 	line-height: 32rpx;
				// 	width: 376rpx;
				// 	height: 42rpx;
				// 	background: #F7F6FA;
				// 	border-radius: 18rpx;
				// 	display: flex;
				// 	align-items: center;
				// 	overflow: hidden;
				// }
			}

			.btn {
				background: #468EFF;
				height: 70rpx;
				line-height: 70rpx;
				font-size: 32rpx;
				text-align: center;
				color: #FFFFFF;
				width: 630rpx;
				margin-top: 50rpx;
				border-radius: 8rpx;
			}

			.qrcode {
				width: 628rpx;
				height: 188rpx;
				margin: 56rpx auto;
				padding: 24rpx;
				box-sizing: border-box;
				display: inline-block;
				background: #fff;
				border-radius: 8rpx;
				border: 1rpx solid #C8C8D4;
				.qrcodeBox {
					display: flex;
					align-items: center;
					justify-content: space-between;
					.title1 {
						display: flex;
						flex-direction: column;
						font-size: 24rpx;
						color: #737482;
						.tit{
							color:#000;
							font-size:32rpx;
							font-weight:600;
						}
						image {
							width: 140rpx;
							height: 33rpx;
						}
					}
				}

				.img {
					width: 140rpx;
					height: 140rpx;
					background-color: #fff; //设置白色背景色
					padding: 6rpx; // 利用padding的特性，挤出白边
					box-sizing: border-box;
				}
			}
		}

		.draw-lots-list {
			height: 68vh;
		}

		.more {
			font-size: 24rpx;
			font-weight: 600;
			color: #C1C1C1;
			text-align: center;
		}

		.nav-box {
			background: #FFFFFF;
			border-radius: 20rpx;
			width: 694rpx;
			margin: 22rpx auto;
			min-height: 436rpx;
			padding: 22rpx 0;
			height: 100%;

			.nav-top {
				display: flex;
				align-items: center;
				justify-content: space-around;
				background: #FFFFFF;
				height: 100rpx;

				.nav-title {
					flex: 1;
					text-align: center;
					font-size: 28rpx;
					font-weight: 600;
					color: #999999;
					line-height: 40rpx;
					position: relative;
				}

				.act {
					color: #131415;
				}

				.act::after {
					content: "";
					position: absolute;
					bottom: -20rpx;
					width: 50rpx;
					height: 6rpx;
					background: #FF7028;
					border-radius: 3rpx;
					left: 50%;
					transform: translateX(-50%);
				}
			}

			.list {
				margin: 30rpx 0;

				.item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-top: 1px solid #f8f8f8;
					padding: 24rpx 34rpx;

					.left {
						font-size: 26rpx;
						font-weight: 400;
						color: #000000;
						.nickname {
							display: inline-block;
							width: 200rpx;
						}
						.sort {
							margin-right: 48rpx;
						}
					}
					
					.right {
						width: 100rpx;
						text-align: right;
					}

					.valid,.right {
						font-size: 26rpx;
						font-weight: 400;
						color: #000000;

						.dw {
							color: #8B8B93;
							margin-left: 10rpx;
						}
					}
					// .valid {
					// 	width: 100rpx;
					// 	text-align: center;
					// }
				}

				.items {
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-top: 1px solid #f8f8f8;
					padding: 24rpx 34rpx;

					.left {
						.name {
							font-size: 26rpx;
							font-weight: 600;
							color: #131415;
							line-height: 36rpx;

						}

						.time {
							font-size: 22rpx;
							color: #8B8B93;
							margin-top: 4rpx;
						}
					}

					.right {
						display: flex;
						align-items: center;
						.ysm {
							width: 80rpx;
							height: 40rpx;
							background: #F5A623;
							border-radius: 4rpx;
							color: #FFFFFF;
							padding: 0 10rpx;
							border-radius: 10rpx;
							margin: 0 16rpx;
							font-size: 22rpx;
							text-align: center;
							line-height: 40rpx;
						}
						.ispay {
							display: flex;
							align-items: center;
							width: 30rpx;
							height: 30rpx;
							// border: 2rpx solid #ccc;
							border-radius: 50%;
							background: #19be6b;
							text-align: center;
							line-height: 30rpx;
						}
					}

					.nyz {
						background: #8B8B93;
					}

				}
			}
		}
	}

	.canvar {
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 100%;
		height: 100vh;
		background: rgba(0, 0, 0, 0.43);
		overflow: hidden;

		z-index: 999::v-deep.uni-canvas {
			margin: 20rpx auto;
		}
	}
</style>
